/*
 * Copyright [2013-2021], Alibaba Group Holding Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.alibaba.polardbx.optimizer.core.rel.ddl;

import com.alibaba.polardbx.optimizer.core.rel.ddl.data.DropStoragePoolPrepareData;
import com.alibaba.polardbx.optimizer.locality.StoragePoolManager;
import org.apache.calcite.rel.core.DDL;
import org.apache.calcite.rel.ddl.DropStoragePool;
import org.apache.calcite.rel.ddl.DropStoragePool;

import java.util.Arrays;
import java.util.stream.Collectors;

import static com.alibaba.polardbx.gms.topology.SystemDbHelper.DEFAULT_DB_NAME;

public class LogicalDropStoragePool extends BaseDdlOperation {
    private DropStoragePool dropStoragePool;

    public DropStoragePoolPrepareData getPreparedData() {
        return preparedData;
    }

    private DropStoragePoolPrepareData preparedData;

    public LogicalDropStoragePool(DDL ddl) {
        super(ddl);
        this.tableName = ddl.getTableName().toString();
        this.dropStoragePool = (DropStoragePool) ddl;
    }

    public static LogicalDropStoragePool create(DDL ddl) {
        return new LogicalDropStoragePool(ddl);
    }

    public void prepareData() {
        DropStoragePoolPrepareData preparedData = new DropStoragePoolPrepareData();
        preparedData.setStoragePoolName(dropStoragePool.getStoragePoolName().toString().toLowerCase());
        if (dropStoragePool.getStoragePoolName().toString().equalsIgnoreCase(StoragePoolManager.ALL_STORAGE_POOL)) {
            preparedData.setDestroyAllStoragePoolInfo(true);
        } else {
            preparedData.setDestroyAllStoragePoolInfo(false);
        }
        preparedData.setSchemaName(DEFAULT_DB_NAME);
        this.preparedData = preparedData;
    }

}
